package com.glc.gao.gavin.rxjavademo.operator;

import android.view.View;

import com.glc.gao.gavin.rxjavademo.R;

import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;

public class MapActivity extends BaseActivity {

    @Override
    public int getDescribeText() {
        return R.string.describe_map;
    }

    @Override
    protected int getContextView() {
        return R.layout.activity_map;
    }

    public void executeCreate(View view) {
        Observable.create(new ObservableOnSubscribe<Integer>() {
            @Override
            public void subscribe(ObservableEmitter<Integer> emitter) throws Exception {
                print("subscribe 111");
                emitter.onNext(111);
                print("subscribe 222");
                emitter.onNext(222);
                print("subscribe 333");
                emitter.onNext(333);
            }
        }).map(new Function<Integer, String>() {
            @Override
            public String apply(Integer integer) throws Exception {
                print("map 111");
                return "我是" + integer;
            }
        }).subscribe(new Consumer<String>() {
            @Override
            public void accept(String s) throws Exception {
                print("accept " + s);
            }
        });
    }
}
